package org.devocean.groupbuying.web.validator;

import org.devocean.groupbuying.domain.Customer;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;


public class PasswordValidator implements Validator {


	public boolean supports(Class<?> classe) {
		
		return Customer.class.isAssignableFrom(classe);
	}


	public void validate(Object target, Errors errors) {
		
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password",
				"required.password", "Field password is required.");
	 
			ValidationUtils.rejectIfEmptyOrWhitespace(errors, "confirmPassword",
					"required.confirmPassword", "Field confirmPassword is required.");
			
			Customer client = (Customer)target;
	 
			if(!(client.getPassword().equals(client.getConfirmPassword()))){
				errors.rejectValue("password", "notmatch.password","not match password");
			}
	}

}
